//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.project.pm.infocheck.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.pm.infocheck.domain.PMInfoCheck;
import com.ruoyi.project.pm.infocheck.mapper.PMInfoCheckMapper;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PMInfoCheckServiceImpl implements PMInfoCheckService {
    @Autowired
    private PMInfoCheckMapper pmInfoCheckMapper;

    public PMInfoCheckServiceImpl() {
    }

    public List<PMInfoCheck> selectPMInfoCheckList(PMInfoCheck pmInfoCheck) {
        return this.pmInfoCheckMapper.selectPMInfoCheckList(pmInfoCheck);
    }

    public int insertPMInfoCheck(PMInfoCheck pmInfoCheck) {
        pmInfoCheck.setInfoChecknCreator(ShiroUtils.getLoginName());
        return this.pmInfoCheckMapper.insertPMInfoCheck(pmInfoCheck);
    }

    public String checkPMInfoCheckNameUnique(PMInfoCheck pmInfoCheck) {
        if (pmInfoCheck.getInfoCheckId() != null && pmInfoCheck.getInfoCheckId() != 0) {
            PMInfoCheck pmInfoCheckResult = this.pmInfoCheckMapper.selectPMInfoCheckById(pmInfoCheck.getInfoCheckId());
            if (pmInfoCheckResult.getInfoCheckType().equals(pmInfoCheck.getInfoCheckType())) {
                return "0";
            }
        }

        Integer infoCheckid = StringUtils.isNull(pmInfoCheck.getInfoCheckId()) ? -1 : pmInfoCheck.getInfoCheckId();
        PMInfoCheck info = this.pmInfoCheckMapper.checkPMInfoNameUnique(pmInfoCheck.getInfoCheckName());
        return StringUtils.isNotNull(info) && info.getInfoCheckId() != infoCheckid ? "1" : "0";
    }

    public PMInfoCheck selectPMInfoCheckById(int infoCheckId) {
        return this.pmInfoCheckMapper.selectPMInfoCheckById(infoCheckId);
    }

    @Override
    public int deletePMInfoCheck(Integer[] ids) {
        return this.pmInfoCheckMapper.deletePMInfoCheck(ids);
    }


}
